home *** CD-ROM | disk | FTP | other *** search
- /* docindex.c - index a new document */
- #include "stdio.h"
- #include "cminor.h"
- #include "document.h"
- #include "btree.h"
- #include "bt_macro.h"
-
- int compf() ;
- int sizef() ;
- #define RW_MODE 2 /* read & write allowed */
- #define EOF_REL 2 /* seek relative to end-of-file */
- long lseek() ;
-
- main(argc,argv)
- int argc ;
- char *argv[] ;
- {
- int ret , datfile ;
- char fn[65] ;
- RECPOS fs, r ;
- IX_DESC ixd ;
- DOCUMENT doc ;
-
- if( argc < 2 )
- { printf(" USAGE: docindex doc-file-name \n") ;
- exit(5) ;
- }
-
- add_str(fn,argv[1],".idx") ;
- if( openix(fn,&ixd,compf,sizef) < 0 )
- { printf(" can't open the index file \n") ;
- exit(10) ;
- }
-
- add_str(fn,argv[1],".dat") ;
- datfile = gopen(fn,RW_MODE,BIN_MODE) ;
- if( datfile < 0 )
- { printf(" can't open the data file \n") ;
- closeix(&ixd) ;
- exit(12) ;
- }
-
- while( 1 ) /* collect and index doc. names */
- { if( input(&doc) <= 0 ) /* get input for next doc. */
- break ; /* exit if at end */
- r = lseek(datfile,0L,EOF_REL) ; /* append the doc. record */
- ret = write(datfile,&doc,sizeof(DOCUMENT) ) ; /* at EOF */
- if( indexit(&doc,r,&ixd) < 0 ) /* index the document */
- { printf(" indexing failed \n") ;
- break ;
- }
- }
- closeix(&ixd) ;
- closeix(datfile) ;
- }
-
-
- int input(pdoc) /* get input describing a document */
- DOCUMENT *pdoc ;
- {
- int ret ;
-
- printf("\n document name (return to quit): ") ;
- ret = getstr(pdoc->dname,NAME_LEN-1) ;
- if( ret <= 0 )
- return( 1 ) ;
- printf(" address to: ") ;
- getstr(pdoc->addressee,ADR_LEN-1) ;
- printf(" date sent (yy/mm/dd): ") ;
- getstr(pdoc->date,DATE_LEN-1) ;
- printf(" subject: ") ;
- getstr(pdoc->subject,SUBJ_LEN-1) ;
- return( 1 ) ;
- }
-
- indexit(pdoc,r,pix) /* index the document */
- DOCUMENT *pdoc ;
- RECPOS r ;
- IX_DESC *pix ;
- {
- ENTRY e ;
-
- e.rptr = r ;
- add_str(e.key,"A*",pdoc->addressee) ;
- if( find_ins(&e,pix) != IX_OK ) ;
- return( -1 ) ;
- add_str(e.key,"D*",pdoc->date) ;
- if( find_ins(&e,pix) != IX_OK ) ;
- return( -1 ) ;
- add_str(e.key,"S*",pdoc->subject) ;
- if( find_ins(&e,pix) != IX_OK ) ;
- return( -1 ) ;
- return( 0 ) ;
- }
-
-
-